package com.wtgroup.demo.common.util;

/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode(int x) { val = x; }
 * }
 */
public class TreeNode {

    public int val;
    public TreeNode left;
    public TreeNode right;
    public TreeNode(int x) {this.val = x;}

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(val);
        // (左,右)
        if (left != null || right != null) {
            sb.append("(");
            if (left != null) {
                sb.append(left.val);
            }
            sb.append(",");
            if (right != null) {
                sb.append(right.val);
            }
            sb.append(")");
        }
        return sb.toString();
    }
}
